package oh.june.kwon.soapClient;

import java.util.Hashtable;
import java.util.Vector;

import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;

public class SoapDataSet 
{
	Hashtable _tables;
	Vector _vector;
	
	public SoapDataSet(SoapObject soapObject){
		_tables = new Hashtable();
		_vector = new Vector();
		
		int propertyCount = soapObject.getPropertyCount();
		String lastTableName = "";
		SoapDataTable lastDataTable = null;
		for(int i = 0 ; i < propertyCount ;i++ )
		{
			PropertyInfo info = new PropertyInfo();
			soapObject.getPropertyInfo(i, null, info);
			String subTableName = info.name;
			if(!lastTableName.equals(subTableName))
			{
				if(!_tables.containsKey(subTableName))
				{
					lastDataTable = new SoapDataTable();
					_tables.put(subTableName, lastDataTable);
					_vector.addElement(lastDataTable);
				}
				else
				{
					lastDataTable = getDataTable(subTableName);
				}
			}
			
			SoapObject rowObject = (SoapObject)soapObject.getProperty(i);
			
			lastDataTable.add(rowObject);
		}
	}
	
	public SoapDataTable getDataTable(String name){
		if(!_tables.containsKey(name))
			return null;

		return (SoapDataTable)_tables.get(name);
	}
	

	public SoapDataTable getDataTable(int index){
		if(_vector.size() <= index)
			return null;

		
		return (SoapDataTable)_vector.elementAt(index);
	}
	
}
